import 'package:flutter/material.dart';

class ClipEditorPainter extends CustomPainter {
  final Offset startlLocation;

  final Offset endLocation;

  final double scrubberAnimationDx;

  final double circleSize;

  final double Widthborder;

  final double Widthscrubber;

  final bool Scrubbershow;

  final Color borderPaint_color;

  final Color circlePaint_color;

  final Color scrubberPaint_color;

  ClipEditorPainter({
    required this.startlLocation,
    required this.endLocation,
    required this.scrubberAnimationDx,
    this.circleSize = 0.5,
    this.Widthborder = 3,
    this.Widthscrubber = 1,
    this.Scrubbershow = true,
    this.borderPaint_color = Colors.white,
    this.circlePaint_color = Colors.white,
    this.scrubberPaint_color = Colors.white,
  });




  @override
  void paint(Canvas canvas, Size size) {
    var borderPaint = Paint()
      ..color = borderPaint_color
      ..strokeWidth = Widthborder
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round;

    var circlePaint = Paint()
      ..color = circlePaint_color
      ..strokeWidth = 1
      ..style = PaintingStyle.fill
      ..strokeCap = StrokeCap.round;

    var scrubberPaint = Paint()
      ..color = scrubberPaint_color
      ..strokeWidth = Widthscrubber
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round;

    final rect = Rect.fromPoints(startlLocation, endLocation);

    if (Scrubbershow) {
      if (scrubberAnimationDx.toInt() > startlLocation.dx.toInt()) {
        canvas.drawLine(
          Offset(scrubberAnimationDx, 0),
          Offset(scrubberAnimationDx, 0) + Offset(0, endLocation.dy),
          scrubberPaint,
        );
      }
    }

    canvas.drawRect(rect, borderPaint);
    canvas.drawCircle(
        startlLocation + Offset(0, endLocation.dy / 2), circleSize, circlePaint);
    canvas.drawCircle(
        endLocation + Offset(0, -endLocation.dy / 2), circleSize, circlePaint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}
